<template>
  <div>
    <!-- "面包屑" -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/">我的订单</a></el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 右侧主体内容 -->
    <el-card style="margin-top: 10px">
      <el-table :data="tableData">
        <el-table-column prop="formid" label="订单号" width="200"></el-table-column>
        <el-table-column prop="tableid" label="座位号" width="200"></el-table-column>
        <el-table-column prop="detail" label="订单详情" width="400"></el-table-column>
        <el-table-column prop="value" label="订单金额"></el-table-column>
        <el-table-column prop="flag" label="订单状态"></el-table-column>
        <el-table-column label="操作">
          <template #default="scope">
            <el-button 
              type="danger" 
              style="min-height: 20px; min-width: 20px; text-align: center" 
              @click="handle_cancel(scope.row)" 
              round
            >
              <el-icon><Delete /></el-icon>
              <span>取 消 订 单</span>
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <!-- 分页组件 -->
    <div style="padding: 10px 0; text-align: center; margin-top: 20px">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
import { Delete } from '@element-plus/icons-vue';

export default {
  name: "Form",
  components: {
    Delete
  },
  data() {
    return {
      tableData: [],
      total: 0,
      pageNum: 1,
      pageSize: 5,
      form: {},
      dish: "",
      totalPrice: 0,
      username: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
    }
  },
  created() {
    this.load();
  },
  methods: {
    load() {
      console.log("tableData", this.tableData);
      // 请求分页相关数据
      request.get("/client/form/select", {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          username: this.username
        }
      }).then(res => {
        this.tableData = res.content.data;
        this.total = res.content.total;
      })
    },
    reset() {
      this.dish = "";
      this.load();
    },
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum;
      this.load();
    },
    handleSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.load();
    },
    handle_cancel(row) {
      this.form = row;
      this.$confirm('此操作将取消该订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handle_cancel_confirm();
      }).catch(() => {
        this.$message.info("已取消操作。");
      })
    },
    handle_cancel_confirm() {
      console.log(this.form);
      request.post("/client/form/cancel", this.form).then(res => {
        if (res.success) {
          this.load();
          this.$message.success(res.message);
        } else {
          this.$message.error(res.message);
        }
      })
    }
  }
}
</script>

<style scoped>

</style>